package main

import (
	"fmt"
	"math/rand"
	"sort"
	"time"
)

//func (r *Rand) GetRandArray(n int, max int) []int {
func CreateRandArray(n int, max int) []int {
	t := time.Now()
	r := rand.New(rand.NewSource(int64(t.Nanosecond())))
	m := make([]int, n)
	// In the following loop, the iteration when i=0 always swaps m[0] with m[0].
	// A change to remove this useless iteration is to assign 1 to i in the init
	// statement. But Perm also effects r. Making this change will affect
	// the final state of r. So this change can't be made for compatibility
	// reasons for Go 1.
	for i := 0; i < n; i++ {
		m[i] = r.Intn(max)
	}
	return m
}
func selecttSort(array []int) {
	arrLen := len(array)
	for i := 0; i < arrLen; i++ {
		max, j := 0, 0
		for j = 1; j < arrLen-i; j++ {
			if array[max] < array[j] {
				max = j
			}
		}
		if max != j-1 {
			array[max], array[j-1] = array[j-1], array[max]
		}

		//		if max != 0 && max != j-1 {
		//			array[max], array[j-1] = array[j-1], array[max]
		//	}
	}
}

func main() {
	//r := rand.New(rand.NewSource(99))
	//r := new(Rand)
	//t := time.Now()
	array := CreateRandArray(100000, 100000)
	//fmt.Println(array)
	//fmt.Println(time.Now().String())
	fmt.Println(time.Now().String())
	selecttSort(array)
	fmt.Println(time.Now().String())
	//fmt.Println(array)
	array = CreateRandArray(100000, 100000)
	//fmt.Println(array)
	fmt.Println(time.Now().String())
	sort.Ints(array)
	fmt.Println(time.Now().String())
	//fmt.Println(array)
}
